Answer: The first person sees two missing hats. He says the sum of those modulo 10. Suppose he says 7 - it could mean that 1 and 6 are missing, or 2 and 5 are missing, or 3 and 4 are missing, or 8 and 9 are missing. However, for the next person in front, she is missing 3 numbers, so just has to total the three numbers modulo 10, and the difference with the first spoken number tells her her hat number. Every person continues in that manner, except when it comes to the person whose hat number is 7. She can not repeat 7, but since she knows one of the missing hat number (or the hat of the first person), she can say that. So all but two are saved.